#include <iostream>  
using namespace std;  
  
#define MAX_SIZE 10  // 定义环形队列的最大容量  
  
class CircularQueue {  
private:  
    int front, rear;  // 队头和队尾指针  
    int data[MAX_SIZE];  // 存储队列元素的数组  
public:  
    CircularQueue() { front = rear = -1; }  // 初始化环形队列  
    bool isFull() { return (rear + 1) % MAX_SIZE == front; }  // 判断环形队列是否已满  
    bool isEmpty() { return front == rear; }  // 判断环形队列是否为空  
    void enqueue(int x) {  // 入队操作  
        if (isFull()) {  
            cout << "Circular queue is full!" << endl;  
            return;  
        }  
        if (isEmpty()) {  
            front = 0;  
        }  
        rear = (rear + 1) % MAX_SIZE;  
        data[rear] = x;  
    }  
    int dequeue() {  // 出队操作  
        if (isEmpty()) {  
            cout << "Circular queue is empty!" << endl;  
            return -1;  
        }  
        int x = data[front];  
        if (front == rear) {  // 队列中只有一个元素  
            front = rear = -1;  
        } else {  
            front = (front + 1) % MAX_SIZE;  
        }  
        return x;  
    }  
    int getFront() {  // 获取队头元素  
        if (isEmpty()) {  
            cout << "Circular queue is empty!" << endl;  
            return -1;  
        }  
        return data[front];  
    }  
};  
  
int main() {  
    CircularQueue q;  
    q.enqueue(1);  
    q.enqueue(2);  
    q.enqueue(3);  
    cout << q.getFront() << endl;  // 输出1  
    cout << q.dequeue() << endl;  // 输出1  
    cout << q.dequeue() << endl;  // 输出2  
    cout << q.dequeue() << endl;  // 输出3  
    cout << q.dequeue() << endl;  // 输出Circular queue is empty!  
    return 0;  
}
